package com.example.monitoringsystem.controller;

import com.example.monitoringsystem.bean.Health;
import com.example.monitoringsystem.bean.User;
import com.example.monitoringsystem.service.HealthService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HealthController {
    @Autowired
    private HealthService healthService;

    @PostMapping( "/health")
    @ResponseBody
    public void getHealthInformation(Health health){
        System.out.println(health);
        healthService.insertHealthInformation(health);
    }

    //查看健康状态
    @GetMapping("/show/health")
    @ResponseBody
    public Health getHealth() {
        Health health = healthService.selectHealthInformation();
        if (health != null){
            return health;
        }
        else {
            return null;
        }
    }

}
